package com.tang.excel.pa.mapper;

import com.tang.excel.pa.domain.EmKnowledgeTestQuestion;
import com.tang.excel.pa.enums.ProtocolType;
import org.apache.ibatis.jdbc.SQL;

import java.util.Objects;

/**
 * @author Tang
 * @classname EmKnowledgeTestQuestionSqlProvider
 * @description [  ]
 * @date 2021/4/20 11:41
 */
public class EmKnowledgeTestQuestionSqlProvider {
    public String sqlByCondition(EmKnowledgeTestQuestion emKnowledgeTestQuestion) {
        SQL sql = new SQL() {
            {
                SELECT("*");
                FROM("em_knowledge_test_question");
                Integer id = emKnowledgeTestQuestion.getId();
                if (Objects.nonNull(id)) {
                    WHERE("id = " + id);
                }
                ProtocolType protocol = emKnowledgeTestQuestion.getProtocol();
                if (Objects.nonNull(protocol)) {
                    WHERE("protocol = " + protocol.getCode());
                }
                ORDER_BY("id");
            }
        };
        return sql.toString();
    }
}